﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace QLNS_Client
{
    public partial class UC_Can_Bo : UserControl
    {
        ServiceReference1.Service_QLNSClient sv = new ServiceReference1.Service_QLNSClient();
        public UC_Can_Bo()
        {
            InitializeComponent();
        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void lb_TonGiao_Click(object sender, EventArgs e)
        {

        }

        private void lb_NamSinh_Click(object sender, EventArgs e)
        {

        }

        private void dateEdit1_EditValueChanged(object sender, EventArgs e)
        {

        }

        private void UC_Can_Bo_Load(object sender, EventArgs e)
        {

            Load_CB();
            //Hiển thị các tùy chọn dân tộc lên combobox
            cmb_DanToc.DataSource = sv.getDT();
            cmb_DanToc.DisplayMember = "TenDT";
            cmb_DanToc.ValueMember = "Ma_DT";
            
            //Hiển thị các tùy chọn tôn giáo lên combobox
            cmb_TonGiao.DataSource = sv.getTG();
            cmb_TonGiao.DisplayMember = "TenTG";
            cmb_TonGiao.ValueMember = "Ma_TG";

            //Hiển thị tùy chọn đơn vị hành chính lên combobox
            cmb_DVHC_CB.DataSource = sv.getDVHC();
            cmb_DVHC_CB.DisplayMember = "TenDVHC";
            cmb_DVHC_CB.ValueMember = "Ma_DV_HC";
        }
        public void Load_CB()
        {
            dataGridView_CanBo.DataSource = sv.getCB();
        }

        private void lb_NgayTuyen_Click(object sender, EventArgs e)
        {

        }

        private void groupControl1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void lb_ThuongBinh_Click(object sender, EventArgs e)
        {

        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void label19_Click(object sender, EventArgs e)
        {

        }

        private void groupBox3_Enter(object sender, EventArgs e)
        {

        }

        private void btn_ThemDVHC_Click(object sender, EventArgs e)
        {
            //UC_DonViHanhChinh ThemDVHC = new UC_DonViHanhChinh();
            //ThemDVHC.Show();
            frm_ThemDVHC ThemDVHC = new frm_ThemDVHC();
            ThemDVHC.ShowDialog();

        }

        private void btn_ThemDT_Click(object sender, EventArgs e)
        {
            frm_ThemDT frmThemDT = new frm_ThemDT();
            frmThemDT.ShowDialog();
        }

        private void btn_ThemGT_Click(object sender, EventArgs e)
        {
            frm_Them_TG ThemTG = new frm_Them_TG();
            ThemTG.ShowDialog();
        }

        private void btn_Them_DangVien_Click(object sender, EventArgs e)
        {
            Them_DangVien ThemDangVien = new Them_DangVien();
            ThemDangVien.ShowDialog();
        }

        private void btn_ThmeNhapNgu_Click(object sender, EventArgs e)
        {
            ThemNhapNgu ThemNhapNgu = new ThemNhapNgu();
            ThemNhapNgu.ShowDialog();
        }

        private void btn_ThemGDCS_Click(object sender, EventArgs e)
        {
            ThemGDCS ThemGDCS = new ThemGDCS();
            ThemGDCS.ShowDialog();
        }

        private void btn_ThemSK_Click(object sender, EventArgs e)
        {
            ThemSK ThemSucKhoe = new ThemSK();
            ThemSucKhoe.ShowDialog();
        }

        private void cmb_DanToc_SelectedIndexChanged(object sender, EventArgs e)
        {
            
        }

        private void dataGridView_CanBo_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void dataGridView_CanBo_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            txt_MaCB.Text = dataGridView_CanBo.CurrentRow.Cells[0].Value.ToString();
            txt_HoTen.Text = dataGridView_CanBo.CurrentRow.Cells[1].Value.ToString();
            txt_TenKhac.Text = dataGridView_CanBo.CurrentRow.Cells[2].Value.ToString();
            date_NamSinh.Text = dataGridView_CanBo.CurrentRow.Cells[3].Value.ToString();
            radioGroup_GT.Text = dataGridView_CanBo.CurrentRow.Cells[4].Value.ToString();
            txt_NoiSinh.Text = dataGridView_CanBo.CurrentRow.Cells[5].Value.ToString();
            txt_QueQuan.Text = dataGridView_CanBo.CurrentRow.Cells[6].Value.ToString();
            txt_HoKhau.Text = dataGridView_CanBo.CurrentRow.Cells[7].Value.ToString();
            txt_ChoO.Text = dataGridView_CanBo.CurrentRow.Cells[8].Value.ToString();
            txt_NgheNghiep.Text = dataGridView_CanBo.CurrentRow.Cells[9].Value.ToString();
            date_NgayTuyen.Text = dataGridView_CanBo.CurrentRow.Cells[10].Value.ToString();
            //cmb_DangVien.Text = dataGridView_CanBo.CurrentRow.Cells[11].Value.ToString();
            //cmb_NhapNgu.Text = dataGridView_CanBo.CurrentRow.Cells[12].Value.ToString();
            cmb_SucKhoe.Text = dataGridView_CanBo.CurrentRow.Cells[13].Value.ToString();
            //cmb_ThuongBinh.Text = dataGridView_CanBo.CurrentRow.Cells[14].Value.ToString();
            txt_SoCMND.Text = dataGridView_CanBo.CurrentRow.Cells[15].Value.ToString();
            date_NgapCapCMND.Text = dataGridView_CanBo.CurrentRow.Cells[16].Value.ToString();
            txt_SoBHXH.Text = dataGridView_CanBo.CurrentRow.Cells[17].Value.ToString();

            txt_NoiCap_BHXH.Text = dataGridView_CanBo.CurrentRow.Cells[19].Value.ToString();
            cmb_DanToc.Text = dataGridView_CanBo.CurrentRow.Cells[20].Value.ToString();
            cmb_TonGiao.Text = dataGridView_CanBo.CurrentRow.Cells[21].Value.ToString();

            cmb_DVHC_CB.Text = dataGridView_CanBo.CurrentRow.Cells[23].Value.ToString();

        }
        public static byte[] ConvertImageToByteArray(System.Drawing.Image imageToConvert, System.Drawing.Imaging.ImageFormat formatOfImage)
        {
            byte[] Ret;
            try
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    imageToConvert.Save(ms, formatOfImage);
                    Ret = ms.ToArray();
                }
            }
            catch (Exception) { throw; }
            return Ret;
        }

        //Hàm mã hóa ảnh
        //use the ImageConverter class under the System.Drawing namespace
        public static byte[] ImageToByte(Image img)
        {
            ImageConverter converter = new ImageConverter();
            return (byte[])converter.ConvertTo(img, typeof(byte[]));
        }

        public static Image byteArrayToImage(byte[] byteArrayIn)
        {
            MemoryStream ms = new MemoryStream(byteArrayIn);
            Image returnImage = Image.FromStream(ms);
            return returnImage;
        }
        public static byte[] ReadImageFromFile(string ImagePath)
        {
            byte[] ImageData = null;
            FileInfo fi = new FileInfo(ImagePath);
            long NumberOfBytes = fi.Length;
            FileStream fs = new FileStream(ImagePath, FileMode.Open, FileAccess.Read);
            BinaryReader br = new BinaryReader(fs);
            ImageData = br.ReadBytes((int)NumberOfBytes);
            return ImageData;
        }
        string tempPath;//FileName dùng để mã hoá ảnh
        private void btn_Anh_CB_Click(object sender, EventArgs e)
        {
            OpenFileDialog op = new OpenFileDialog();
            op.Filter = "jpg|*.jpg|png|*.png|bitmap|*.bmp|all file|*.*";
            if (op.ShowDialog() == DialogResult.OK)
            {
                pic_CB.Image = Image.FromFile(op.FileName);
                tempPath = op.FileName;
            }
        }

    
    }
}
